﻿package mortal.component.window.resWin
{
    import com.gengine.resource.*;
    import mortal.component.window.*;
    import mortal.game.manager.window3d.*;
    import mortal.mvc.interfaces.*;

    public class ResBaseWindow extends BaseWindow implements IResWin
    {
        private var _isLoadComplete:Boolean = false;
        private var _uiRes:String;
        private var _rect3DObject:Rect3DObject;

        public function ResBaseWindow(param1:ILayer = null, param2:String = null)
        {
            this._uiRes = param2;
            super(param1);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            if (this.hasRes)
            {
                LoaderHelp.addResCallBack(this._uiRes, this.onResLoadComplete);
            }
            else
            {
                this._isLoadComplete = true;
                this.layoutUI();
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._isLoadComplete = false;
            this.disposeRect3DObject();
            return;
        }// end function

        private function onResLoadComplete() : void
        {
            this._isLoadComplete = true;
            this.layoutUI();
            this.refresh(true);
            return;
        }// end function

        public function layoutUI() : void
        {
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show(param1, param2);
            if (this.rect3DObject)
            {
                Rect3DManager.instance.windowShowHander(null, this);
            }
            this.refresh(true);
            return;
        }// end function

        public function display(param1:int = 0, param2:int = 0) : void
        {
            if (this.isHide)
            {
                this.show(param1, param2);
            }
            return;
        }// end function

        public function refresh(param1:Boolean = false) : void
        {
            if (this.allowRefresh && param1)
            {
                this.loadData();
            }
            return;
        }// end function

        protected function get allowRefresh() : Boolean
        {
            return !isHide && this.isLoadComplete;
        }// end function

        protected function loadData() : void
        {
            return;
        }// end function

        public function get isLoadComplete() : Boolean
        {
            return this._isLoadComplete;
        }// end function

        private function get hasRes() : Boolean
        {
            return this._uiRes && this._uiRes != "";
        }// end function

        public function get rect3DObject() : Rect3DObject
        {
            if (this._rect3DObject == null)
            {
                this._rect3DObject = this.createRect3DObject();
            }
            return this._rect3DObject;
        }// end function

        protected function createRect3DObject() : Rect3DObject
        {
            return null;
        }// end function

        protected function disposeRect3DObject() : void
        {
            if (this._rect3DObject)
            {
                Rect3DManager.instance.disposeRect3d(this._rect3DObject);
                this._rect3DObject = null;
            }
            return;
        }// end function

    }
}
